<template>
  <div class="info" v-loading="loading">
    <div class="card_con mb15">
      <el-row class="mb15">
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">订单号：</div>
          <el-input
            clearable
            v-model="orderId"
            placeholder="请输入订单号"
          ></el-input>
        </el-col>
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">订单状态：</div>
          <el-select clearable v-model="deliverId" placeholder="请选择">
            <el-option
              v-for="item in deliverArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <div class="fz13 mb10">&nbsp;</div>
          <el-button type="primary" @click="handleQuery">查询</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="card_con">
      <el-table
        border
        :data="tableData"
        :header-cell-style="{
          'text-align': 'center',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        highlight-current-row
      >
        <el-table-column prop="id" label="id" min-width="15%">
        </el-table-column>
        <el-table-column prop="oid" label="订单号" min-width="25%">
        </el-table-column>
        <el-table-column prop="prices.actual" label="订单金额" min-width="20%">
        </el-table-column>
        <el-table-column prop="price" label="房型信息" min-width="20%">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.product" :key="index">
              <div class="room_info">
                <div>床型：</div>
                <div>{{ item.product_name }}</div>
              </div>
              <div class="room_info">
                <div>价格：</div>
                <div>{{ item.price }}</div>
              </div>
              <div class="room_info">
                <div>数量：</div>
                <div>{{ item.num }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="times.pay_time" label="付款时间" min-width="25%">
        </el-table-column>
        <el-table-column prop="status" label="状态" min-width="25%">
          <template slot-scope="scope">
            <div v-if="scope.row.status === '待消费'" class="red">待消费</div>
            <div v-if="scope.row.status === '待支付'" class="orange">
              待支付
            </div>
            <div v-if="scope.row.status === '已完成'" class="green">已完成</div>
            <div v-if="scope.row.status === '已消费'">已消费</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="35%">
          <template slot-scope="scope">
            <div class="caozuo">
              <div
                v-if="scope.row.status === '待消费'"
                class="handleExamine hand_cs"
                @click="handleGo(scope.row)"
              >
                入住
              </div>
              <div class="handleEdit hand_cs" @click="handleDetail(scope.row)">
                详情
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <Pagination :page="page" @onCurrentChange="handleCurrentChange" />
      </div>
      <!-- <el-dialog
        class="editDialog"
        title="详情"
        :visible.sync="dialogVisible"
        width="800px"
      >
        <Dialog v-if="dialogVisible" :rowData="rowData"></Dialog>
      </el-dialog> -->
    </div>
  </div>
</template>

<script>
// import Dialog from "./order_detail.vue";
import Pagination from "@/components/Pagination.vue";
import { hotelOrder, toLive } from "@/api/shopSystem";
export default {
  components: { Pagination },
  data() {
    return {
      loading: true,
      orderId: "",
      deliverId: "",
      deliverArr: [
        { id: "待支付", name: "待支付" },
        { id: "待消费", name: "待消费" },
        { id: "已完成", name: "已完成" },
        { id: "已消费", name: "已消费" },
      ],
      dialogVisible: false,
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      title: "",
      tableData: [],
      rowData: {}, //当前行数据 传给详情
    };
  },
  methods: {
    //订单列表
    async hotelOrder() {
      const { data, err } = await hotelOrder({
        page: this.page.pageNum,
        oid: this.orderId,
        deliverId: this.deliverId,
      });
      if (err === 0) {
        this.loading = false;
        this.tableData = data.data;
        this.page.total = data.total;
        this.page.pageSize = data.per_page;
      }
    },
    //去入住接口
    async toLive(oid) {
      const { msg, err } = await toLive({
        oid,
      });
      if (err === 0) {
        this.$message({
          showClose: true,
          message: "操作成功",
          type: "success",
        });
        this.hotelOrder();
      } else {
        this.$message({
          showClose: true,
          message: msg,
          type: "error",
        });
      }
    },
    //查询
    handleQuery() {
      this.loading = true;
      //调接口
      this.page.pageNum = 1;
      this.hotelOrder();
    },
    //查看详情
    handleDetail(row) {
      this.dialogVisible = true;
      this.rowData = row;
    },
    // 当前页: ${val}
    handleCurrentChange(val) {
      this.loading = true;
      this.page.pageNum = val;
      this.hotelOrder();
    },
    //去入住
    handleGo(row) {
      this.$confirm("是否确认入住?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.toLive(row.oid);
        })
        .catch(() => {});
    },
  },
  created() {
    this.hotelOrder();
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/index.scss";
.room_info {
  display: flex;
}
.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
.el-select {
  width: 100%;
}

.tb {
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
}
.row {
  display: flex;
  border-radius: 2px;
  border: 1px solid #ccc;
  width: 80px;
  .l {
    width: 80px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;

    i {
      margin-right: 6px;
      font-size: 18px;
    }
    &:hover {
      cursor: pointer;
    }
  }
  .l:nth-child(3) {
    border-right: 0;
  }
}
.editDialog {
  //   z-index: 2005 !important;
  /deep/.el-dialog {
    height: 75%;
    .el-dialog__body {
      height: 78%;
      overflow: auto;
    }
  }
}
.handleExamine {
  margin-right: 20px;
}
.togoodsDialog {
  padding: 0 40px 0 0;
  box-sizing: border-box;
}
.orange {
  color: orange;
}
</style>
<style>
.v-modal {
  z-index: 2000 !important;
}
</style>
